package cn.ad.server.domain.ad;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

public class AdMaterial implements Serializable {

	private static final long serialVersionUID = 7006980481504886993L;

	static final String VERSION = "0";
	static final String CACHE_NAME = "admaterial";

	private long id;
	private Creative creative;
	private long creativeId;
	private int duration;
	private int materialTypeId;
	private int materialFormat;
	private String materialUrl;
	private String materialText;
	private AdSize adSize;
	private int status;
	private Date createTime;
	private Date updateTime;
	private List<Integer> platformIds;
	private List<AuditPassedMarker> AuditPassedMarkers;
	

	public List<AuditPassedMarker> getAuditPassedMarkers() {
		return AuditPassedMarkers;
	}

	public void setAuditPassedMarkers(List<AuditPassedMarker> auditPassedMarkers) {
		AuditPassedMarkers = auditPassedMarkers;
	}

	public static String cacheKey(long id) {
		return new StringBuilder(CACHE_NAME).append(":").append(VERSION).append(":").append(id).toString();
	}

	public String toCacheKey() {
		return new StringBuilder(CACHE_NAME).append(":").append(VERSION).append(":").append(this.getId()).toString();
	}
	
	public double computeD(double aWidth, double aHeight) {
		double d = 0.0;
		if (adSize == null)
			return d;
		double a = (this.getAdSize().getWidth() * aWidth + this.getAdSize().getHeight() * aHeight)
				/ ((Math.sqrt(this.getAdSize().getWidth() * this.getAdSize().getWidth()
						+ this.getAdSize().getHeight() * this.getAdSize().getHeight()))
				* Math.sqrt(aWidth * aWidth + aHeight * aHeight));
		if (a < -1)
			a = -1.0d;
		if (a > 1)
			a = 1.0d;
		d = Math.acos(a);
		return Math.abs(d);
	}


	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Creative getCreative() {
		return creative;
	}

	public void setCreative(Creative creative) {
		this.creative = creative;
	}

	public int getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public int getMaterialTypeId() {
		return materialTypeId;
	}

	public void setMaterialTypeId(int materialTypeId) {
		this.materialTypeId = materialTypeId;
	}

	public int getMaterialFormat() {
		return materialFormat;
	}

	public void setMaterialFormat(int materialFormat) {
		this.materialFormat = materialFormat;
	}

	public String getMaterialUrl() {
		return materialUrl;
	}

	public void setMaterialUrl(String materialUrl) {
		this.materialUrl = materialUrl;
	}

	public String getMaterialText() {
		return materialText;
	}

	public void setMaterialText(String materialText) {
		this.materialText = materialText;
	}

	public AdSize getAdSize() {
		return adSize;
	}

	public void setAdSize(AdSize adSize) {
		this.adSize = adSize;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public long getCreativeId() {
		return creativeId;
	}

	public void setCreativeId(long creativeId) {
		this.creativeId = creativeId;
	}

	public List<Integer> getPlatformIds() {
		return platformIds;
	}

	public void setPlatformIds(List<Integer> platformIds) {
		this.platformIds = platformIds;
	}

	public boolean equals(Object arg0) {
		if(arg0 instanceof AdMaterial){			
			return this.id==((AdMaterial)arg0).id;
		}else{
			return super.equals(arg0);
		}
	}
	
	public int hashCode() {
		return Long.valueOf(id).hashCode();
	}
	

}
